$(function () {
  $.post('/admin_getHeadAndNickname', (res) => {
    if (res.code == 1) {
      $(".avatar").attr('src', res.data.avatar);
      $('.name').text(res.data.nickname);;
    }
  });

  (function () {
    // console.log(location.pathname);
    let postArr = ['/admin/posts', '/admin/post-add', '/admin/categories'];
    let settingArr = ['/admin/nav-menus', '/admin/slides', '/admin/settings'];
    if (postArr.indexOf(location.pathname) != -1) {
      $("#menu-posts").addClass('show').attr('aria-expanded', 'true').prev().removeClass('collapsed').attr('aria-expanded', 'true');
      // $("#menu-posts").addClass('in').attr('aria-expanded', 'true').prev().removeClass('collapsed').removeAttr('data-toggle').attr('aria-expanded', 'true');
    }
    if (settingArr.indexOf(location.pathname) != -1) {
      $("#menu-settings").addClass('show').attr('aria-expanded', 'true').prev().removeClass('collapsed').attr('aria-expanded', 'true');
    }
    // 当前高亮
    let eleId = location.pathname.substring(7);
    if (!eleId) {
      eleId = 'index';
    }
    $("#" + eleId).addClass('active');
  })();
});